﻿using System;
using System.Linq.Expressions;
using System.Windows;
using System.Windows.Controls;

namespace CrateMayhem.Desktop
{
    public static class UIElementCollectionExtensions
    {
        public static UIElement First(this UIElementCollection collection, Expression<Func<UIElement, bool>> expression)
        {
            foreach (var child in collection)
            {
                if (expression.Compile().Invoke(child as UIElement)) return child as UIElement;
            }

            return null;
        }
    }
}